<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Tile</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
      <link href="css/bootstrap.css" rel="stylesheet">
      <link href="css/bootstrap-responsive.css" rel="stylesheet">
      <link href="js/bootstrap.js" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<?php
include("/usr/local/apache2/htdocs/jibaiwang/lib/Tile.php");
include("/usr/local/apache2/htdocs/jibaiwang/lib/ImgStorage.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/bootstrap/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Tiles"]['qlogtag'];
Logger::configure($defarray["Series"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Tiles"]["host"];
$user = $defarray["Tiles"]["user"];
$pass = $defarray["Tiles"]["pass"];
$db = $defarray["Tiles"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Tile($dbh,$logger);
$texture_arr = array(
    "大理石"=>"大理石",
    "水磨石"=>"水磨石", 
    "花岗岩"=>"花岗岩", 
    "木质"=>"木质", 
);

$class_arr = array(
    "天花板砖"=>"天花板砖",
    "地板砖"=>"地板砖",
    "腰线"=>"腰线",
    "墙砖"=>"墙砖",
    );

$tile_id = $_REQUEST["tile_id"];
$tile_number = $_REQUEST["tile_number"];
$tile_length = $_REQUEST["tile_length"];
$tile_width = $_REQUEST["tile_width"];
$tile_texture = $_REQUEST["tile_texture"];
$tile_img = $_REQUEST["tile_img"];
$tile_class = $_REQUEST["tile_class"];
$submit = $_REQUEST["submit"];
$tile_series = $_REQUEST["tile_series"];
$list = $s->getListWithAvgPriceBySeriesID($tile_series);
if($submit != "")
{
    $res = $s->updateTileByID($tile_number, $tile_length, $tile_width, $tile_texture,$tile_class, $tile_img, $tile_img, $tile_series, $tile_id);
    header("Location:Tile.php?tile_series=$tile_series");
}
if($_REQUEST["op"] == "del")
{
    $res = $s->deleteTileByID($_REQUEST["rule_id"]);
    header("Location:Tile.php?tile_series=$tile_series");
}
?>
  <div class="navbar">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="Series.php">返回系列首页</a>
          <div class="nav-collapse">
            <ul class="nav">
            <li><a href="TileDiagram.php?tile_series=<?php echo $tile_series;?>">效果图模式</a></li>
            <li class="active"><a href="Tile.php?tile_series=<?php echo $tile_series;?>">列表模式</a></li>
            </ul>
          </div><!-- /.nav-collapse -->
        </div>
      </div><!-- /navbar-inner -->
    </div><!-- /navbar -->

<div id="myModal" class="modal hide fade">

<div class="modal-header">
<a class="close" data-dismiss="modal" >&times;</a>
<h3>新建瓷砖产品</h3>
</div>

<div class="modal-body">
<h4>请填写以下信息</h4>
<p>
<form method="post" enctype="multipart/form-data" class="form-horizontal" action="Tile_add.php">
<fieldset>
<div class="control-group">
<span class="help-inline">型号:</span>
<input type="text" name="tile_number" class="span1" placeholder="输入型号">
<input type="hidden" name="tile_series" class="span1" value="<?php echo $tile_series;?>">
</div>

<div class="control-group input-prepend input-append">
<span class="help-inline">尺寸:</span>
<input type="text" name="tile_length" class="input-mini span1" placeholder="宽"><span class="add-on">mm</span>
<i class="icon-remove"></i>
<input type="text" name="tile_width" class="span1" placeholder="高"><span class="add-on">mm</span>
</div>

<div class="control-group" >
<span class="help-inline">材质:</span>
<select class="span2" name="tile_texture">
<option>请选择</option>
<option>大理石</option>
<option>水磨石</option>
<option>花岗岩</option>
<option>木质</option>
</select>
</div>

<div class="control-group input-prepend input-append" >
<span class="help-inline">类型:</span>
<select class="span2" name="tile_class">
<option>请选择</option>
<option>天花板砖</option>
<option>地板砖</option>
<option>腰线</option>
<option>墙砖</option>
</select>
</div>

<div class="control-group">
<label class="control-label" for="tile_img">上传图片,注意<a href="#" class="tooltip-test" title="请使用300x300,300x450,300x600,400x800mm图片">尺寸</a>:</label>
<div class="controls">
<input class="input-file" name="tile_img" id="tile_img" type="file">
</div>
</div>
</fieldset>
</p>
<hr>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-large" data-dismiss="modal" >关闭</a>
<button type="submit" class="btn btn-warning btn-large">添加</button>
</div>
</form>
</div>

<a data-toggle="modal" href="#myModal" class="btn btn-warning btn-large">添加新瓷砖</a>

<div class="row">
<?php
$str = "";
foreach($list as $key => $value)
{ 
    $id = $value["id"];
    $number = $value["number"];
    $length = $value["length"];
    $width = $value["width"];
    $texture = $value["texture"];
    $img = $value["img"];
    $class= $value["class"];
    $avg_price = $value["avg_price"];
    $str .= '
        <div class="span4">
  <a onclick="modify_del('.$id.','.$tile_series.')" class="close" data-dismiss="modal" >&times;</a>
  <form class="well form-inline" target="_self">
         <input type="hidden" name="tile_id" class="span1" value="'.$id.'">
         <input type="hidden" name="tile_img" class="span1" value="'.$img.'">
         <input type="hidden" name="tile_series" class="span1" value="'.$tile_series.'">

         <div class="control-group input-prepend input-append">
         <ul class="thumbnails">
         <li class="span3">
         <a href="#" class="thumbnail">
         <img src="http://www.hongdouxiong.com/jibaiwang/'.$img.'" alt="">
         </a>
         </li>
         </ul>
         </div>

         <div class="control-group input-prepend input-append">
         <span class="help-inline">型号:</span>
         <input type="text" name="tile_number" class="span1" value="'.$number.'">
         </div> 

         <div class="control-group input-prepend input-append">
         <span class="help-inline">尺寸:</span>
         <input type="text" name="tile_length" class="input-mini span1" value="'.$length.'"><span class="add-on">mm</span>
         <i class="icon-remove"></i>
         <input type="text" name="tile_width" class="span1" value="'.$width.'"><span class="add-on">mm</span>
         </div>

         <div class="control-group input-prepend input-append" >
         <span class="help-inline">材质:</span>
         <select class="span2" name="tile_texture">
         <option value="">请选择</option>';
         foreach($texture_arr as $texture_idx => $texture_name)
         {
            if($texture_idx == $texture)
                $str .= '<option selected value="'.$texture_idx.'">'.$texture_name.'</option>';
            else
                $str .= '<option value="'.$texture_idx.'">'.$texture_name.'</option>';
         }
         $str .= '</select>
         </div>
         <div class="control-group input-prepend input-append" >
         <span class="help-inline">类型:</span>
         <select class="span2" name="tile_class">
         <option value="">请选择</option>';
         foreach($class_arr as $class_idx => $class_name)
         {
             if($class_idx == $class)
                 $str .= '<option selected value="'.$class_idx.'">'.$class_name.'</option>';
             else
                 $str .= '<option value="'.$class_idx.'">'.$class_name.'</option>';
         } 
         $str .= '</select>
         </div>

         <div class="control-group ">
         <span class="help-inline">经销商<a href="#" class="tooltip-test" title="这是根据您所有经销商设置的价格计算出来的平均值">均价</a>:</span>
         <input type="text" readonly class="span1" value="'.$avg_price.'">
         </div>


         <button value="1" type="submit" name="submit" class="btn btn-warning btn-large" >保存修改</button>
         <button onclick="modify_del('.$id.','.$tile_series.')" type="submit" class="btn btn-danger btn-large" >删除</button>
         </form>
         </div>
         ';
    
}
echo $str;
?>
</div>

      <!-- Le javascript
      ================================================== -->
      <!-- Placed at the end of the document so the pages load faster
      <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> -->
      <script src="js/jquery.js"></script>
      <script src="js/google-code-prettify/prettify.js"></script>
      <script src="js/bootstrap-transition.js"></script>
      <script src="js/bootstrap-alert.js"></script>
      <script src="js/bootstrap-modal.js"></script>
      <script src="js/bootstrap-dropdown.js"></script>
      <script src="js/bootstrap-scrollspy.js"></script>
      <script src="js/bootstrap-tab.js"></script>
      <script src="js/bootstrap-tooltip.js"></script>
      <script src="js/bootstrap-popover.js"></script>
      <script src="js/bootstrap-button.js"></script>
      <script src="js/bootstrap-collapse.js"></script>
      <script src="js/bootstrap-carousel.js"></script>
      <script src="js/bootstrap-typeahead.js"></script>
      <script src="js/application.js"></script>
      <script src="js/customize.js"></script>

      <script type="text/javascript">
      function modify_del(id,tile_series){
                if(window.confirm("确定删除吗？")){
                    str="?op=del&rule_id="+id+"&tile_series="+tile_series
                      window.open(str,'_self');
                }
      }
      </script>
</html>
